#include "seatest.h"

#include "cmtr_int.h"

//
// create a test...
//
void test_hello_world()
{
        char *s = "hello world!";
        assert_string_equal("hello world!", s);
        assert_string_contains("hello", s);
        assert_string_doesnt_contain("goodbye", s);
        assert_string_ends_with("!", s);
        assert_string_starts_with("hell", s);
}

void test_cmtr_int()
{
        cmtr_matrix m;
        cmtr_init_int(&m, 3,5);
        assert_int_equal(sizeof(int), m.sizeof_item);
        assert_int_equal(3, m.iRows);
        assert_int_equal(5, m.jCol);
        
        cmtr_destroy(&m);
        assert_int_equal(0, m.sizeof_item);
        assert_int_equal(0, m.iRows);
        assert_int_equal(0, m.jCol);
}

void cristu()
{
	cmtr_matrix cr_mtrx;
	cmtr_init(&cr_mtrx, sizeof(int), 4, 7);
	int val = 1;
	cmtr_fill(&cr_mtrx, &val);
	val = 22;
	cmtr_set(&cr_mtrx, 2,2, &val);
	val = 33;
	cmtr_set(&cr_mtrx, 3,3, &val);
	val = *(int*)cmtr_get(&cr_mtrx, 2,2);
	cmtr_set(&cr_mtrx, 0,0, &val);
	cmtr_printf_int(&cr_mtrx);

        printf("creo trasposta\n"); fflush(stdout);
        cmtr_matrix* t_cr_mtrx = cmtr_transp(&cr_mtrx);
        printf("stampo trasposta\n");fflush(stdout);
	cmtr_printf_int(t_cr_mtrx);
        cmtr_destroy(t_cr_mtrx);
	cmtr_destroy(&cr_mtrx);

	cmtr_matrix cr_mtrx1;
	cmtr_init(&cr_mtrx1, sizeof(float), 5, 11);
	float fval = 0.3;
	cmtr_fill(&cr_mtrx1, &fval);
	cmtr_printf_flt(&cr_mtrx1);

        cmtr_matrix* t_cr_mtrx1 = cmtr_transp(&cr_mtrx1);
	cmtr_printf_flt(t_cr_mtrx1);
        cmtr_destroy(t_cr_mtrx1);
	cmtr_destroy(&cr_mtrx1);
}


//
// put the test into a fixture...
//
void test_fixture_hello( void )
{
        test_fixture_start();      
        run_test(test_hello_world);
        run_test(test_cmtr_int);      
        run_test(cristu);
        test_fixture_end();       
}

//
// put the fixture into a suite...
//
void all_tests( void )
{
        test_fixture_hello();   
        cristu();
}

//
// run the suite!
//
int main( int argc, char** argv )
{     //deve uscire con 0 per make
       //TODO uscire con 0 solo se tutti i test sono passed 
       //return run_tests(all_tests);
       run_tests(all_tests);
       return 0;
}
